﻿using ML.Utils;
using System.Configuration;
using System.Web;

namespace ML.Plug
{
    /// <summary>
    /// 微信配置文件
    /// </summary>
    public static class WechatConfig
    {
        /// <summary>
        /// 微信appId(公众号的唯一标识)
        /// </summary>
        public static string appId
        {
            get
            {
                return ConfigurationManager.AppSettings["TenPayV3_AppId"];
            }
        }

        /// <summary>
        /// 微信secret
        /// </summary>
        public static string secret
        {
            get
            {
                return ConfigurationManager.AppSettings["TenPayV3_AppSecret"];
            }
        }

        /// <summary>
        /// 微信回调地址
        /// </summary>
        public static string redirect_url
        {
            get
            {
                string url = ConfigurationManager.AppSettings["WechatRedirect"];
                return HttpUtility.UrlEncode(url);
            }
        }

        /// <summary>
        /// 返回类型，请填写code
        /// </summary>
        public static string response_type = "code";

        /// <summary>
        /// 	应用授权作用域，snsapi_base （不弹出授权页面，直接跳转，只能获取用户openid），snsapi_userinfo （弹出授权页面，可通过openid拿到昵称、性别、所在地。并且， 即使在未关注的情况下，只要用户授权，也能获取其信息 ）
        /// </summary>
        public static string scope = "snsapi_userinfo";

        /// <summary>
        /// 组装授权地址
        /// </summary>
        public static string rerurnUrl
        {
            get
            {
                string url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type={2}&scope={3}&state={4}#wechat_redirect", appId, redirect_url, response_type, scope, CommonUtil.ReadDateTime());
                return url;
            }
        }
    }
}